package com.xujl.fastlib.utils;

import android.app.Application;

/**
 * @author xujl
 * @email 597355068@qq.com
 * @Date on 2019/6/18
 * @Description 配置管理器
 */
public class ConfigManager {
    private Application mContext;
//   private boolean isDebug = BuildConfig.DEBUG;
     private boolean isDebug = true;
    private ApiLoginInvalidListener mLoginInvalidListener;

    public static ConfigManager getInstance () {
        return Holder.MANAGER;
    }

    private ConfigManager () {
    }

    public boolean isDebug () {
        return isDebug;
    }

    public void setDebug (boolean debug) {
        isDebug = debug;
    }

    public void init (Application application) {
        mContext = application;
        application.registerActivityLifecycleCallbacks(AppManager.getAppManager());
    }

    public Application getContext () {
        return mContext;
    }

    private static class Holder {
        private static final ConfigManager MANAGER = new ConfigManager();
    }

    public void setLoginInvalidListener (ApiLoginInvalidListener loginInvalidListener) {
        mLoginInvalidListener = loginInvalidListener;
    }

    public void doLoginInvalid (String code, String msg) {
        if (mLoginInvalidListener != null) {
            mLoginInvalidListener.onLoginInvalid(code, msg);
        }
    }

    /**
     * 登录失效
     */
    public interface ApiLoginInvalidListener {
        void onLoginInvalid (String code, String msg);
    }

}
